package swd.work.dataview_wizard_fld_conf;

import com.pub.database.*;
import java.util.*;
import javax.servlet.http.*;
import com.pub.web.*;

public class Action {
   QueryBean gqbnDAO=null;
   @SuppressWarnings("unchecked")
   public String action(javax.servlet.jsp.PageContext pageContext){
      HttpServletRequest request=(HttpServletRequest)pageContext.getRequest();
      HttpServletResponse response=(HttpServletResponse)pageContext.getResponse();
      View view=(View)request.getAttribute("view");

      (new WebFunction()).setPortal_to_session(request); //set session from portal
      if (request.getSession().getAttribute("u_id")==null) {
         try{
            request.getRequestDispatcher((new StringBuffer("login.jsp")).insert(0,"/").toString()).forward(request,response);
            return "login";
         }
         catch(Exception le){
            view.setOnloadScript("can not redirect to login page...please contact IT");
            return "";
         }
      }

      gqbnDAO=new QueryBean(view.getDBAlias(),view.getDBDebug(),view.getSourceCharset(),view.getTargetCharset());

      Business business=new Business(gqbnDAO);

      String paraname;
      String paravalue;
      Hashtable lhtTableData=null;

      try{
    	  lhtTableData = new Hashtable();
          if(view.getPrgAction()!=null && view.getPrgAction().equals("save")){
              Enumeration<Object> names = request.getParameterNames();
              while (names.hasMoreElements())
              {
                  paraname = (String) names.nextElement();		//轉換變數名成字串
                  //System.out.println(appname + " = " +request.getParameter(appname));
                  paravalue = request.getParameter(paraname).toString();
                  if(paravalue!=null && paravalue!=""){
                      lhtTableData.put(paraname, paravalue);
                      System.out.println(paraname+"====>"+paravalue);
                  }
              }

          }

          //view.setfldhidden();
          business.setInitScreenForSave(view);
         return "";
      }
      catch(Exception e){
         view.setOnloadScript("alert('Program error please contact IT.');");
         return "";
      }
      finally{
         try{
            if(gqbnDAO!=null){
               gqbnDAO.close();
            }
         }
         catch(Exception e){
            System.out.println("can not close querybean in Action.java");
         }
      }
   }
}
